package com.el.init;

import java.util.ArrayList;
import java.util.List;

import com.el.logger.ELogger;
import com.el.logger.EventLogDispatcher;
import com.el.loggers.ConsoleELogger;

public class EventLogConfigurator {

    private static EventLogConfigurator configurator;

    static {
        if (configurator == null) {
            configurator = new EventLogConfigurator();
            configurator.init();
        }
    }
    
    private List<ELogger> eLoggers = new ArrayList<ELogger>();
    private EventLogDispatcher eventLogDispatcher = new EventLogDispatcher();
    
    private EventLogConfigurator() {
        
    }
    
    private void init() {
        // read config

        //create eLoggers - refactor this!
//        eLoggers.add(new ServerELogger());
//        eLoggers.add(new FlatFileELogger());
        eLoggers.add(new ConsoleELogger());
        
        //init all eLoggers
        for (ELogger eLogger : eLoggers) {
            eLogger.init();
        }
        
        eventLogDispatcher.setLogs(eLoggers);
    }
    
    public static List<ELogger> getActiveELoggers() {
        return EventLogConfigurator.configurator.getELoggers();
    }
    
    public static EventLogDispatcher getLogDispatcher() {
        return EventLogConfigurator.configurator.getEventLogDispatcher();
    }
    
    private List<ELogger> getELoggers() {
        return eLoggers;
    }
    
    private EventLogDispatcher getEventLogDispatcher() {
        return eventLogDispatcher;
    }
    
    public void finalize() {
        //close all eloggers
        for (ELogger eLogger : eLoggers) {
            eLogger.close();
        }
    }
}
